<template>
  <div class="block">
    <div v-if="!userListManage">
      <Error></Error>
    </div>
    <div v-if="userListManage">
      <!--详情-->
      <el-drawer id="drawer"
                 size="45%"
                 title="二维码详情"
                 :visible.sync="drawer"
                 :direction="direction"
                 :before-close="handleClose">
        <div class="drawerDiv">
            <p v-if="detailsData.length !== 0" v-for="(item,index) in detailsData" style="float: left;width: 150px;margin: 10px">
              <img :src="item.img_url" :key="index" width="150" />
              <span style="vertical-align: middle;width: 150px;text-align: center;display: inline-block">{{item.name}}</span>
            </p>
          <p v-if="detailsData.length === 0">暂无数据</p>
        </div>
      </el-drawer>
      <!--海报详情-->
      <el-drawer
                 size="45%"
                 title="海报详情"
                 :visible.sync="drawers"
                 :direction="direction"
                 :before-close="handleClose">
        <div class="drawerDiv">
          <p v-if="detailsDatas.length !== 0" v-for="(item,index) in detailsDatas" style="float: left;width: 150px;margin: 10px">
            <img :src="item.img_url" :key="index" width="150" />
            <span style="vertical-align: middle;width: 150px;text-align: center;display: inline-block">{{item.time}}</span>
          </p>
          <p v-if="detailsDatas.length === 0">暂无数据</p>
        </div>
      </el-drawer>
      <!--收藏详情-->
      <el-drawer
        size="45%"
        title="收藏详情"
        :visible.sync="collectDrawer"
        :direction="direction"
        :before-close="handleClose">
        <div class="drawerDiv">
          <div style="font-size: 20px;font-weight: 600;margin-top: 10px">我的海报</div>
          <p v-if="collect_list.length !== 0" v-for="(item,index) in collect_list" style="float: left;width: 150px;margin: 10px">
            <img :src="item" :key="index" width="150" />
          </p>
          <p v-if="collect_list.length === 0">暂无数据</p>
          <div style="font-size: 20px;float: left;width: 100%;font-weight: 600;margin-top: 10px">我的朋友圈</div>
          <div v-if="article_list.length !== 0" v-for="(item,index) in article_list" style="float: left;width: 80%;margin: 10px">
            <p>{{item.ac_content}}</p>
            <img v-for="(items,indexs) in item.img_list" :src="items" :key="indexs" width="25%" style="margin: 10px"/>
          </div>
          <p v-if="article_list.length === 0">暂无数据</p>
        </div>
      </el-drawer>
      <div class="inquireDiv">
        <p>
          <label><span>关注状态：</span>
            <el-select v-model="form.status" placeholder="请选择状态">
              <el-option v-for="(item,key,index) in statusObj" :label="item" :value="key" :key="index"></el-option>
            </el-select>
          </label>
          <label><span>开始时间：</span>
            <el-date-picker
              v-model="form.start_time"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择日期">
            </el-date-picker>
          </label>
          <label><span>结束时间：</span>
            <el-date-picker
              v-model="form.end_time"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择日期">
            </el-date-picker>
          </label>
          <el-button type="primary" @click="examineFn" style="float: right">查 询</el-button>
        </p>
      </div>
      <div class="tableDiv" v-loading="loading">
        <el-row>
          <el-table
            :cell-class-name="addClass"
            :data="tableData"
            border
            stripe>
            <el-table-column
              type="index"
              align="center"
              width="50"
              label="序号">
            </el-table-column>
            <el-table-column
              prop="name"
              label="微信昵称"
              align="center"
              width="300"
            >
            </el-table-column>
            <el-table-column
              label="微信头像"
              align="center"
              width="150">
              <template slot-scope="scope">
                <el-popover placement="top-start" title="" trigger="click">
                  <img :src="scope.row.img_url" alt="" style="width: 250px;cursor: pointer">
                  <img slot="reference" :src="scope.row.img_url" style="width: 60px;cursor: pointer">
                </el-popover>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="subscribe"
              label="关注状态"
              width="100">
            </el-table-column>
            <el-table-column
              prop="time"
              sortable
              label="创建时间"
              align="center"
              width="200"
            >
            </el-table-column>
            <el-table-column
              align="center">
              <template slot="header" slot-scope="scope">
                <div class="el-table-header"></div>
              </template>
              <template slot-scope="scope">
                <el-button
                  @click.native.prevent="detailsRow(scope.$index,tableData)"
                  type="primary"
                  size="small">
                  我的二维码
                </el-button>
                <el-button
                  @click.native.prevent="detailsRowPop(scope.$index,tableData)"
                  type="warning"
                  size="small">
                  我的海报
                </el-button>
                <el-button
                  @click.native.prevent="collectRowPop(scope.$index,tableData)"
                  type="success"
                  size="small">
                  我的收藏
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-col :span="24">
            <div class="block" v-if="total">
              <el-pagination
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-size="10"
                layout="total, prev, pager, next"
                :total="total">
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
  import Error from '../errorPage/errorPage401'
  export default {
    data() {
      return {
        mid: '',
        drawer: false,
        drawers: false,
        collectDrawer: false,
        direction: 'rtl',
        detailsData: [],
        detailsDatas: [],
        collect_list: [],
        article_list: [],
        uid:'',

        loading: true,
        currentPage: '',
        tableData: [],
        total: '',
        userListManage:false,
        dialogFormVisible:false,
        form: {
          start_time: '',
          end_time: '',
          status:''
        },
        statusObj:{}
      }
    },
    methods: {
      //初始化
      initFn: function (page) {
        this.form.end_time = this.form.end_time ==null ? '' : this.form.end_time;
        this.form.start_time = this.form.start_time ==null ? '' : this.form.start_time;
        let data = {
          page: page,
          status:this.form.status,
          startTime:this.form.start_time,
          endTime:this.form.end_time,
        };
        let str = this.encryptionAesRsa(data);
        let encryptData = str.split('%$#@zjt@#$%')[0];
        let encryptKey = str.split('%$#@zjt@#$%')[1];
        let incomData = {
          map: 'api_article_userList',
          plum_session_api: localStorage.getItem('token'),
          encryptData: encryptKey,
          encryptKey: encryptData
        };
        this.$http.post('', incomData).then((data) => {
          if (data.ec == 200) {
            this.loading = false;
            this.total = Number(data.data.count);
            this.currentPage = Number(data.data.page);
            this.tableData = data.data.list;
            this.statusObj = data.data.status;
          } else if (data.ec == 401) {
            this.$message.error(data.em);
            setTimeout(() => {
              this.exitLogin();
            }, 1500)
          } else {
            this.$message.error(data.em);
          }
        }).catch((err) => {
          this.$message.error('error!');
        })
      },
      //查询
      examineFn: function () {
        this.initFn(1)
      },
      //列变色
      addClass({row, column, rowIndex, columnIndex}) {
        if (columnIndex === 5) {
          return 'cell-blue'
        }
      },
      //点击分页
      handleCurrentChange(val) {
        this.$router.replace({
          path: this.$route.path,
          query: {
            page: val,
          }
        });
        this.loading = true;
        this.initFn(val);
      },
      //点击详情
      detailsRow(index, row) {
        this.drawer = true;
        this.uid = row[index].id;
        this.confirmUser();
      },
      //点击海报详情
      detailsRowPop(index, row) {
        this.drawers = true;
        this.uid = row[index].id;
        this.confirmUserPop();
      },
      //点击我的收藏
      collectRowPop(index, row) {
        this.collectDrawer = true;
        this.uid = row[index].id;
        this.collectUserPop();
      },
      //获取详情
      confirmUser: function () {
        let data = {
          id: this.uid,
        };
        let str = this.encryptionAesRsa(data);
        let encryptData = str.split('%$#@zjt@#$%')[0];
        let encryptKey = str.split('%$#@zjt@#$%')[1];
        let incomData = {
          map: 'api_posters_myqrode',
          plum_session_api: localStorage.getItem('token'),
          encryptData: encryptKey,
          encryptKey: encryptData
        };
        this.$http.post('', incomData).then((data) => {
          if (data.ec == 200) {
            this.detailsData = data.data.list
          } else if (data.ec == 401) {
            this.$message.error(data.em);
            setTimeout(() => {
              this.exitLogin();
            }, 1500)
          } else {
            this.$message.error(data.em);
          }
        }).catch((err) => {
          this.$message.error('error!');
        })
      },
      //获取海报详情
      confirmUserPop: function () {
        let data = {
          id: this.uid,
        };
        let str = this.encryptionAesRsa(data);
        let encryptData = str.split('%$#@zjt@#$%')[0];
        let encryptKey = str.split('%$#@zjt@#$%')[1];
        let incomData = {
          map: 'api_posters_myShare',
          plum_session_api: localStorage.getItem('token'),
          encryptData: encryptKey,
          encryptKey: encryptData
        };
        this.$http.post('', incomData).then((data) => {
          if (data.ec == 200) {
            this.detailsDatas = data.data.list
          } else if (data.ec == 401) {
            this.$message.error(data.em);
            setTimeout(() => {
              this.exitLogin();
            }, 1500)
          } else {
            this.$message.error(data.em);
          }
        }).catch((err) => {
          this.$message.error('error!');
        })
      },
      //获取收藏详情
      collectUserPop: function () {
        let data = {
          id: this.uid,
        };
        let str = this.encryptionAesRsa(data);
        let encryptData = str.split('%$#@zjt@#$%')[0];
        let encryptKey = str.split('%$#@zjt@#$%')[1];
        let incomData = {
          map: 'api_posters_mycollect',
          plum_session_api: localStorage.getItem('token'),
          encryptData: encryptKey,
          encryptKey: encryptData
        };
        this.$http.post('', incomData).then((data) => {
          if (data.ec == 200) {
            this.collect_list = data.data.collect_list;
            this.article_list = data.data.article_list;
          } else if (data.ec == 401) {
            this.$message.error(data.em);
            setTimeout(() => {
              this.exitLogin();
            }, 1500)
          } else {
            this.$message.error(data.em);
          }
        }).catch((err) => {
          this.$message.error('error!');
        })
      },
      //关闭详情弹窗
      handleClose(done) {
        done();
      },
    },
    mounted() {
      this.currentPage = this.$route.query.page ? this.$route.query.page : 1;
      this.initFn(this.currentPage);
      // 按钮权限
      let buttonMenu = localStorage.getItem('buttonMenu');
      buttonMenu = this.edecryptButton(buttonMenu);
      //页面权限
      if (buttonMenu.indexOf('userListManage') !== -1) {
        this.userListManage = true
      }
    },
    components:{
      Error
    }
  }
</script>

<style scoped>
  .inquireDiv {
    padding: 30px;
    background: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)
  }

  .inquireDiv label {
    display: inline-block;
    margin-left: 50px;
  }
  .inquireDiv label span{
    width: 80px;
    display: inline-block;
  }

  .inquireDiv .el-input {
    width: 220px;
  }

  .tableDiv {
    margin-top: 20px;
  }

  .el-col {
    border-radius: 4px;
    height: 75px;
    background-color: #fff;
  }

  .tableDiv >>> .el-pagination {
    height: 30px;
    line-height: 30px;
    margin-top: 25px;
    text-align: center;
  }

  .tableDiv >>> .cell-blue {
    color: #409EFF !important;
  }

  .drawerDiv {
    width: 100%;
    height: calc(90vh);
    padding: 20px;
    overflow-y: auto;
    box-sizing: border-box;
  }

  .drawerDiv h2 {
    text-align: center;
    font-size: 20px;
    margin: 20px 0;
  }

  .drawerDiv p {
    font-size: 16px;
    color: #000000;
    margin-top: 10px;
  }

  .drawerDiv p label {
    font-size: 16px;
    vertical-align: middle;
    font-weight: 600;
    display: inline-block;
    width: 100px;
    text-align: right;
  }

  .drawerDiv p span {
    font-size: 14px;
    vertical-align: middle;
    color: #555555;
    margin-left: 5px;
  }

  .el-table-header >>> .el-button {
    float: right;
    height: 40px;
  }
  .block >>> .el-dialog {
    width: 500px;
  }


  .block >>> .uploadingImage{
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    width: 200px;
    height: 355px;
    display: inline-block;
    vertical-align: middle;
    transition: all .2s;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center center;

  }
  .block >>> .uploadingImage:hover{
    border: 1px dashed #409EFF;
  }
  .block >>> .uploadingImage i{
    font-size: 30px !important;
    color: #555555;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -16px;
    margin-top: -15px;
  }
</style>



